﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

using LibraryModels;
using LibraryIDAL;
using Microsoft.ApplicationBlocks.Data;
using GotDotNet.ApplicationBlocks.Data;
using LibraryUtility.Data;

namespace LibraryBLL.BookBLL
{
    public class BookTypeBLL
    {
        private static readonly string conn = LibraryUtility.Common.ConnConfig.ConnString;
        private static readonly LibraryIDAL.ITabBookType bookType = LibraryDALFactory.DataAccess.CreateTabBookType();

        /// <summary>
        /// 添加图书类型
        /// </summary>
        /// <param name="booktype">图书类型</param>
        /// <returns>布尔值</returns>
        public bool AddBookType(TabBookType booktype)
        {
            try
            {
                if (bookType.Add(booktype) > 0)
                    return true;
                else
                    return false;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }

        /// <summary>
        /// 删除图书类型
        /// </summary>
        /// <param name="typeId">图书类型编号</param>
        /// <returns>布尔值</returns>
        public bool DelBookType(int typeId)
        {
            try
            {
                if (bookType.Delete(typeId) > 0)
                    return true;
                else
                    return false;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }

        /// <summary>
        /// 查询所有图书类型(查询图书类型用到,带搜索)
        /// </summary>
        /// <returns>数据信息</returns>
        public string GetAllBookType(string message)
        {
            JSONHelper jsonHelp = new JSONHelper();
            jsonHelp.success = true;
            DataSet ds = bookType.GetAllBookType(message);
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                jsonHelp.AddItem("TypeID", dr["TypeID"].ToString());
                jsonHelp.AddItem("TypeName", dr["TypeName"].ToString());
                jsonHelp.AddItem("Remark", dr["Remark"].ToString());
                jsonHelp.ItemOk();
            }
            string str = jsonHelp.ToString();
            return str;
        }


        /// <summary>
        /// 根据类型Id查询所有图书信息(状态为空闲)
        /// </summary>
        /// <param name="TypeId"></param>
        /// <returns></returns>
        public string GetBookByTypeId(int TypeId)
        {
            JSONHelper jsonHelp = new JSONHelper();
            jsonHelp.success = true;
            DataSet ds = bookType.GetRoomByTypeId(TypeId);
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                jsonHelp.AddItem("BookID", dr["BookID"].ToString());
                jsonHelp.AddItem("BookNumber", dr["BookNumber"].ToString());
                jsonHelp.ItemOk();
            }
            string str = jsonHelp.ToString();
            return str;
        }
    }
}
